package com.briup.mt.web.controller;

import com.briup.mt.bean.Article;
import com.briup.mt.bean.Category;
import com.briup.mt.service.ArticleService;
import com.briup.mt.service.CategoryService;
import com.briup.mt.utils.Message;
import com.briup.mt.utils.MessageUtil;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.constraints.NotNull;
import java.util.List;

@RestController
@Validated
@RequestMapping("/Category")
public class CategoryController {
    @Resource
    private CategoryService categoryService;

    @GetMapping("query")
    public Message query(String name, String description){
        List<Category> list =  categoryService.query(name, description);
        return MessageUtil.success(list);
    }

    @PostMapping("saveOrUpdate")
    public Message saveOrUpdate(Category category){
        categoryService.saveOrUpdate(category);
        return MessageUtil.success("操作成功");
    }

    @DeleteMapping("deleteById")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "用户编号", required = true, paramType = "query"),
    })
    public Message deleteById( @NotNull Long id){
        categoryService.deleteById(id);
        return MessageUtil.success("操作成功");
    }
}
